'use client'; import { useState } from 'react'; import { fetchApi } from '@/lib/utils/client'; import { useStudioContext } from '@/app/studio/context'; import type { CrewItem } from '@/types/response/crew/list'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Checkbox } from '@/components/ui/checkbox'; function RequiredLabel({ htmlFor, children }: { htmlFor: string; children: React.ReactNode }) { return ; } function MoneyInput({ id, value, onChange, placeholder }: { id: string; value: string|number; onChange: (v: string) => void; placeholder?: string }) { const [focused, setFocused] = useState(false); const raw = String(value); const display = focused || !raw ? raw : (Number(raw) ? Number(raw).toLocaleString() : raw); return ( onChange(e.target.value)} onFocus={() => setFocused(true)} onBlur={() => setFocused(false)} /> ); } type Props = { crew: CrewItem; onUpdated: () => void; }; export default function CrewSettingsTab({ crew, onUpdated }: Props) { const { channelID } = useStudioContext(); const [form, setForm] = useState({ name: crew.name, description: crew.description ?? '', minAmount: crew.minAmount ?? ('' as string|number), isActive: crew.isActive }); const [saving, setSaving] = useState(false); const handleSave = async () => { if (!form.name.trim()) { alert('크루명을 입력해 주세요.'); return; } setSaving(true); try { await fetchApi('/api/studio/crew/save', { method: 'POST', body: { channelID, id: crew.id, name: form.name, description: form.description || undefined, minAmount: form.minAmount !== '' ? Number(form.minAmount) : undefined, isActive: form.isActive } }); alert('저장되었습니다.'); onUpdated(); } catch (err: unknown) { alert(err instanceof Error ? err.message : '저장에 실패했습니다.'); } finally { setSaving(false); } }; return (
이 금액 이상 후원한 회원만 크루에 가입할 수 있습니다.